package top.aiprogram.attend.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.aiprogram.attend.entity.Attend;
import top.aiprogram.attend.service.AttendService;
import top.aiprogram.attend.vo.QueryCondition;
import top.aiprogram.common.page.PageQueryBean;
import top.aiprogram.user.entity.User;

import javax.servlet.http.HttpSession;

/**
 * Created by HP on 2018/10/16.
 */
@Controller
@RequestMapping("attend")
public class AttendController {

    @Autowired
    private AttendService attendService;
    /*
    @Author JackQi {www.coder520.com}
    @DATE 2018/10/16 21:55
    @Description: 配置进入打卡页面
    */
    @RequestMapping
    public String getAttend(){
        return "attend";
    }

    /*
    @Author JackQi {www.coder520.com}
    @DATE 2018/10/17 8:58
    @Description: 进行签到
    */
    @RequestMapping("signattend")
    public String signAttend(@RequestBody Attend attend){
        attendService.doAttend(attend);
        return "succ";


    }
    /*
    @Author JackQi {www.coder520.com}
    @DATE 2018/10/17 19:08
    @Description:根据前端传递的信息,获取相应的信息,关于分页所使用的信息
    */
    @RequestMapping("signattendlist")
    @ResponseBody
    public PageQueryBean listAttend(QueryCondition condition, HttpSession httpSession){
        User userinfo =(User) httpSession.getAttribute("userinfo");
        String[] split = condition.getRangeDate().split("/");
        condition.setStartDate(split[0]);
        condition.setEndDate(split[1]);
        condition.setUserId(userinfo.getId());
        PageQueryBean pageQueryBean= attendService.listAttend(condition);
        return pageQueryBean;
    }
}
